<script setup lang="ts">
import { Form, FormSchema } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { PropType, reactive, watch } from 'vue'
import { useValidator } from '@/hooks/web/useValidator'
import { ElDescriptions, ElDescriptionsItem, ElTag } from 'element-plus'

const { required, lengthRange } = useValidator()

const props = defineProps({
  formSchema: {
    type: Array as PropType<FormSchema[]>,
    default: () => []
  },
  selectedTickets: {
    type: Array as PropType<any[]>,
    default: () => []
  },
  selectedTeam: {
    type: String as PropType<String>,
    default: null
  }
})

const rules = reactive({
  title: [required(), lengthRange({ max: 100 })],
  content: [required()]
})

const { formRegister, formMethods } = useForm()
const { setValues, getFormData, getElFormExpose } = formMethods

const submit = async () => {
  const elForm = await getElFormExpose()
  const valid = await elForm?.validate().catch((err) => {
    console.log(err)
  })
  if (valid) {
    return await getFormData()
  }
}

defineExpose({
  submit
})
</script>

<template>
  <ElDescriptions :column="1" class="pl-5">
    <!-- <ElDescriptionsItem label="班组号">
      <ElTag>{{ props.selectedTeam }}</ElTag>
    </ElDescriptionsItem> -->
    <ElDescriptionsItem label="工单号">
      <ElTag :key="i" v-for="i in props.selectedTickets" class="mr-5px">
        {{ i }}
      </ElTag>
    </ElDescriptionsItem>
  </ElDescriptions>
  <Form :rules="rules" @register="formRegister" :schema="formSchema" :is-col="false" />
</template>
